package dbapi

import (
	"GO_BACK/model/db"
	"fmt"
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func PgDbConnect() (*gorm.DB, error) {
	dbconfig := db.InitPgDB()
	dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable",
		dbconfig.Host, dbconfig.Username, dbconfig.Password, dbconfig.Dbname, dbconfig.Port)
	pgdb, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		return nil, err
	}
	return pgdb, err
}
